package com.practice.system.service.impl;

import com.practice.system.mapper.DeviceInfoMapper;
import com.practice.system.pojo.DeviceInfo;
import com.practice.system.service.DeviceInfoService;
import com.practice.utils.PageUtils;
import com.practice.utils.Query;
import com.practice.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DeviceInfoServiceImpl implements DeviceInfoService {

    @Autowired
    DeviceInfoMapper deviceInfoMapper;

    @Override
    public R queryPage(Map<String, Object> params) {
        new Query().setStartPage(params);
        List<DeviceInfo> list = deviceInfoMapper.findDeviceByPage(params);
        long count = deviceInfoMapper.getDeviceCount(params);
        PageUtils<DeviceInfo> page = new PageUtils<>(list, count);
        return R.ok().put("page", page);
    }

    @Override
    public R updateInfo(DeviceInfo deviceInfo) {
        if (deviceInfo.getDeviceName() == null) {
            return R.error("名称必须存在！");
        }
        Integer b = deviceInfoMapper.updateInfo(deviceInfo);
        if (b == 1) {
            return R.ok("修改成功！");
        }
        return R.error("修改失败!");
    }
}
